package cn.iocoder.yudao.module.yyzx.controller.admin.nurse_level_content;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotations.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.yyzx.controller.admin.nurse_level_content.vo.*;
import cn.iocoder.yudao.module.yyzx.dal.dataobject.nurse_level_content.NurseLevelContentDO;
import cn.iocoder.yudao.module.yyzx.service.nurse_level_content.NurseLevelContentService;

@Tag(name = "管理后台 - 护理级别对应的护理内容")
@RestController
@RequestMapping("/yyzx/nurse-level-content")
@Validated
public class NurseLevelContentController {

    @Resource
    private NurseLevelContentService nurseLevelContentService;

    @PostMapping("/create")
    @Operation(summary = "创建护理级别对应的护理内容")
    @PreAuthorize("@ss.hasPermission('yyzx:nurse-level-content:create')")
    public CommonResult<Integer> createNurseLevelContent(@Valid @RequestBody NurseLevelContentSaveReqVO createReqVO) {
        return success(nurseLevelContentService.createNurseLevelContent(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新护理级别对应的护理内容")
    @PreAuthorize("@ss.hasPermission('yyzx:nurse-level-content:update')")
    public CommonResult<Boolean> updateNurseLevelContent(@Valid @RequestBody NurseLevelContentSaveReqVO updateReqVO) {
        nurseLevelContentService.updateNurseLevelContent(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除护理级别对应的护理内容")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('yyzx:nurse-level-content:delete')")
    public CommonResult<Boolean> deleteNurseLevelContent(@RequestParam("id") Integer id) {
        nurseLevelContentService.deleteNurseLevelContent(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得护理级别对应的护理内容")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('yyzx:nurse-level-content:query')")
    public CommonResult<NurseLevelContentRespVO> getNurseLevelContent(@RequestParam("id") Integer id) {
        NurseLevelContentDO nurseLevelContent = nurseLevelContentService.getNurseLevelContent(id);
        return success(BeanUtils.toBean(nurseLevelContent, NurseLevelContentRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得护理级别对应的护理内容分页")
    @PreAuthorize("@ss.hasPermission('yyzx:nurse-level-content:query')")
    public CommonResult<PageResult<NurseLevelContentRespVO>> getNurseLevelContentPage(@Valid NurseLevelContentPageReqVO pageReqVO) {
        PageResult<NurseLevelContentDO> pageResult = nurseLevelContentService.getNurseLevelContentPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, NurseLevelContentRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出护理级别对应的护理内容 Excel")
    @PreAuthorize("@ss.hasPermission('yyzx:nurse-level-content:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportNurseLevelContentExcel(@Valid NurseLevelContentPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<NurseLevelContentDO> list = nurseLevelContentService.getNurseLevelContentPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "护理级别对应的护理内容.xls", "数据", NurseLevelContentRespVO.class,
                        BeanUtils.toBean(list, NurseLevelContentRespVO.class));
    }

}